package com.qf.smartdevice.controller;

import com.qf.smartdevice.dot.Result;
import com.qf.smartdevice.dot.UserDto;
import com.qf.smartdevice.pojo.SysUserInfo;
import com.qf.smartdevice.service.SysUserInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author 王博康
 * @version 1.0
 * @project devicemanagementsystem
 * @description: TODO
 * @date 2022/3/16 15:57 星期三
 */
@RestController
@RequestMapping("/user")
public class SysUserInfoController {
    private SysUserInfoService sysUserInfoService;
    @Autowired
    public void setSysUserInfoService(SysUserInfoService sysUserInfoService) {
        this.sysUserInfoService = sysUserInfoService;
    }
    @PostMapping("/registry")
    public Result registry(@RequestBody UserDto userDto){
        SysUserInfo sysUserInfo = new SysUserInfo();
        BeanUtils.copyProperties(userDto,sysUserInfo );
        sysUserInfoService.addUserInfo(sysUserInfo);
        return Result.setOk();
    }
    @PostMapping("/login")
    public Result login(@RequestBody UserDto userDto, HttpSession session ){
        SysUserInfo sysUserInfo = sysUserInfoService.login(userDto);
        session.setAttribute("user",sysUserInfo );
        return Result.setOk();
    }




}
